﻿using System;
using System.Threading.Tasks.Sources;
using System.Xml;
using System.Xml.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Data;
using static ConsoleApp2.Program;

namespace ConsoleApp2
{
    internal class Program
    {
        //abstract class Persion
        //{
        //    public abstract int ID(int a);
        //    public abstract void Print(int a);
        //}

        //class student : Persion
        //{
        //    public override void Print(int a){
        //        Console.WriteLine("学生:{0}", ID(a));
        //    }

        //    public override int ID(int a){
        //        _id = a;
        //        return _id;
        //    }
        //    private int _id = 0;
        //}

        //class teacher : Persion
        //{
        //    public override void Print(int a){
        //        Console.WriteLine("老师:{0}", ID(a));
        //    }
        //    public override int ID(int a){
        //        _id = a;
        //        return _id;
        //    }
        //    private int _id = 0;
        //}

        //class FactoryPersion
        //{
        //    public static Persion createFactory(string str)
        //    {
        //        Persion s = null;
        //        if (str.Equals("student"))
        //        {
        //            s = new student();
        //        }
        //        else if (str.Equals("teacher"))
        //        {
        //            s = new teacher();
        //        }
        //        return s;
        //    }          
        //}

        //abstract class createPersion
        //{
        //    public abstract Persion CreatePersion();
        //}

        //class teacherFactory : createPersion {
        //    public override Persion CreatePersion()
        //    {
        //        return new teacher();
        //    }
        //}

        //class studentFactory : createPersion
        //{
        //    public override Persion CreatePersion()
        //    {
        //        return new student();
        //    }
        //}


        //static void Main(string[] args)
        //{
        //    FactoryPersion.createFactory("student").Print(3);
        //    FactoryPersion.createFactory("teacher").Print(2);

        //    createPersion pp = null;
        //    pp = new studentFactory();
        //    pp.CreatePersion().Print(1);

        //    pp = new teacherFactory();
        //    pp.CreatePersion().Print(2);
        //}

        //abstract class Factory
        //{
        //    public abstract Yabo createYabo();
        //    public abstract Yajia createYajia();
        //}

        //class NanFactory : Factory
        //{
        //    public override Yabo createYabo()
        //    {
        //        return new NanchangYabo();
        //    }
        //    public override Yajia createYajia()
        //    {
        //        return new NanchangYajia();
        //    }
        //}
        //class shangFactory : Factory
        //{
        //    public override Yabo createYabo()
        //    {
        //        return new ShangYabo();
        //    }
        //    public override Yajia createYajia()
        //    {
        //        return new ShangYajia();
        //    }
        //}

        //abstract class Yabo
        //{
        //    public abstract void Print();
        //}
        //abstract class Yajia
        //{
        //    public abstract void Print();
        //}

        //class NanchangYabo : Yabo
        //{
        //    public override void Print()
        //    {
        //        Console.WriteLine("NanchangYabo");
        //    }
        //}
        //class NanchangYajia :Yajia
        //{
        //    public override void Print()
        //    {
        //        Console.WriteLine("NanchangYajia");
        //    }
        //}

        //class ShangYabo : Yabo
        //{
        //    public override void Print()
        //    {
        //        Console.WriteLine("ShangYabo");
        //    }
        //}

        //class ShangYajia : Yajia
        //{
        //    public override void Print()
        //    {
        //        Console.WriteLine("ShangYajia");
        //    }
        //}

        //static void Main()
        //{
        //    Factory factory = null;
        //    factory = new NanFactory();
        //    factory.createYabo().Print();
        //    factory.createYajia().Print();

        //    factory = new shangFactory();
        //    factory.createYabo().Print();
        //    factory.createYajia().Print();
        //}

        //internal class Computer
        //{
        //    private List<string> patterns = new List<string>();

        //    public void AddPart(string part)
        //    {
        //        patterns.Add(part);
        //    }

        //    public void Print()
        //    {
        //        Console.WriteLine("电脑开始组装:");
        //        foreach (string e in patterns)
        //        {
        //            Console.WriteLine($"开始组装零部件: {e}");
        //        }
        //        Console.WriteLine("电脑完成组装");
        //    }
        //}

        //internal class Director
        //{
        //    public void Construct(Bulider build)
        //    {
        //        build.BuildPartCpu();
        //        build.BuildPartMainBoard();
        //    }
        //}



        //internal class B1 : Bulider
        //{
        //    Computer computer = new Computer();

        //    public override void BuildPartCpu()
        //    {
        //        computer.AddPart("CPU 1");
        //    }
        //    public override void BuildPartMainBoard()
        //    {
        //        computer.AddPart("Main 1");
        //    }
        //    public override Computer GetComputer()
        //    {
        //        return computer;
        //    }
        //}
        //internal class B2 : Bulider
        //{
        //    Computer computer = new Computer();

        //    public override void BuildPartCpu()
        //    {
        //        computer.AddPart("CPU 2");
        //    }
        //    public override void BuildPartMainBoard()
        //    {
        //        computer.AddPart("Main 2");
        //    }
        //    public override Computer GetComputer()
        //    {
        //        return computer;
        //    }
        //}
        //internal class B3 : Bulider
        //{
        //    Computer computer = new Computer();

        //    public override void BuildPartCpu()
        //    {
        //        computer.AddPart("CPU 3");
        //    }
        //    public override void BuildPartMainBoard()
        //    {
        //        computer.AddPart("Main 3");
        //    }
        //    public override Computer GetComputer()
        //    {
        //        return computer;
        //    }


        //    static void Main(string[] args)
        //    {
        //        Director director = new Director();
        //        Bulider bulider = null;

        //        bulider = new B1();
        //        director.Construct(bulider);
        //        bulider.GetComputer().Print();

        //        bulider = new B2();
        //        director.Construct(bulider);
        //        bulider.GetComputer().Print();

        //        bulider = new B3();
        //        director.Construct(bulider);
        //        bulider.GetComputer().Print();
        //    }
        //}

        class Info
        {
            public int Id;
            public string Name;

            public Info(int id, string name)
            {
                Id = id;
                Name = name;
            }
        }
        class Prototype
        {
            public int Age;
            public Info info;

            public Prototype DeepCopy()
            {
                Prototype prototype = (Prototype)this.MemberwiseClone();
                prototype.info = new (info.Id, info.Name);
                return prototype;
            }

            public Prototype ShallowCopy()
            {
                return this.MemberwiseClone() as Prototype;
            }
        }

        static void Main(string[] args)
        {
            Prototype p1 = new Prototype();
            p1.Age = 18;
            p1.info = new Info(7, "zhangsan");

            Prototype p2 = p1.DeepCopy();

            Prototype p3 = p1.ShallowCopy();

            Console.WriteLine($"{p1.info.Id}{p1.info.Name} {p1.Age}");
            Console.WriteLine($"{p2.info.Id}{p2.info.Name} {p2.Age}");
            Console.WriteLine($"{p3.info.Id}{p3.info.Name} {p3.Age}");

            p1.Age = 35;
            p1.info.Name = "sssss";
            p1.info.Id = 50;

            Console.WriteLine($"{p1.info.Id}{p1.info.Name} {p1.Age}");
            Console.WriteLine($"{p2.info.Id}{p2.info.Name} {p2.Age}");
            Console.WriteLine($"{p3.info.Id}{p3.info.Name} {p3.Age}");
        }
    }

    
}
